// 部门管理路由
import { Router } from 'express';
import { authMiddleware } from '@/middlewares/auth.middleware';
import { permissionMiddleware } from '@/middlewares/permission.middleware';
import { dataScopeMiddleware } from '@/middlewares/dataScope.middleware';
import deptController from '@/controllers/system/dept.controller';
import { validateDeptCreate, validateDeptUpdate, validateDeptRemove } from '@/validators/system/dept.validator';
import { createController } from '@/utils/router/route.controller';

const router = createController(Router());

/**
 * 部门管理路由
 * 路径前缀：/system/dept
 */

// ================== 部门相关 ==================

// 所有路由均需认证
router.use(authMiddleware);

// 获取部门列表
router.get('/list', dataScopeMiddleware(), permissionMiddleware('system:dept:list'), deptController.list);

// 查询部门列表(排除节点)
router.get('/list/exclude/:deptId', dataScopeMiddleware(), permissionMiddleware('system:dept:list'), deptController.listExcludeChild);

// 查询部门详细
router.get('/:deptId', permissionMiddleware('system:dept:query'), deptController.getInfo);

// 查询部门下拉树结构
router.get('/treeselect', dataScopeMiddleware(), deptController.treeSelect);

// 根据角色ID查询部门树结构
router.get('/roleDeptTreeselect/:roleId', dataScopeMiddleware(), deptController.roleDeptTreeSelect);

// ================== 新增、修改、删除 ==================

// 新增部门（自动记录操作日志）
router.POST('', permissionMiddleware('system:dept:add'), validateDeptCreate, deptController.add);

// 修改部门（自动记录操作日志）
router.PUT('', permissionMiddleware('system:dept:edit'), validateDeptUpdate, deptController.update);

// 删除部门（自动记录操作日志）
router.DELETE('/:deptId', permissionMiddleware('system:dept:remove'), validateDeptRemove, deptController.remove);

export default router; 